package lanou.giftsay_01.fragment.mine;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import lanou.giftsay_01.tools.GiftUser;
import lanou.giftsay_01.R;
import lanou.giftsay_01.adapter.MineRvAdapter;
import lanou.giftsay_01.tools.NewBean;
import lanou.giftsay_01.tools.BaseFragment;
import lanou.giftsay_01.tools.DBTool;

/**
 * Created by dllo on 16/8/30.
 */
public class SecondFragment extends BaseFragment {

    private DBTool dbTool;
    private RecyclerView rv;

    /**
     //             * 这是本地数据库的
     //             */
//            dbTool.querySingleCollection(" nickName = ?" ,giftUser.getUsername(), new DBTool.QueryListener() {
//                @Override
//                public void onQueryComplete(ArrayList<NewBean> arrayList) {
//                    MineRvAdapter mineRvAdapter = new MineRvAdapter(mContext);
//                    mineRvAdapter.setNewBeen(arrayList);
//                    rv.setAdapter(mineRvAdapter);
//                    Log.d("SecondFragment", "走这里了");
//                }
//            });

    @Override
    public void onResume() {
        super.onResume();
        dbTool = DBTool.getInstance();
        GiftUser giftUser = BmobUser.getCurrentUser(GiftUser.class);
        if (giftUser != null) {
            /**
             * 从云端获取的
             */
            BmobQuery<NewBean> query = new BmobQuery<>();
            query.addWhereEqualTo("nickName" ,giftUser.getUsername());
            query.setLimit(100);
            query.findObjects(new FindListener<NewBean>() {
                @Override
                public void done(List<NewBean> list, BmobException e) {
                    MineRvAdapter mineRvAdapter = new MineRvAdapter(mContext);
                    ArrayList<NewBean> arrayList = (ArrayList<NewBean>) list;
                    mineRvAdapter.setNewBeen(arrayList);
                    rv.setAdapter(mineRvAdapter);
                }
            });

        }
    }




    @Override
    protected int setLayout() {
        return R.layout.fragment_sdleft;   }

    @Override
    protected void initView() {

        rv = (RecyclerView) getView().findViewById(R.id.mine_vp_rv);
        GridLayoutManager manager =  new GridLayoutManager(mContext , 2);
        rv.setLayoutManager(manager);

    }

    @Override
    protected void initData() {




    }
}
